﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
using BLL;
using System.Data.SqlClient;

namespace _3tiers
{
    public partial class Form4SuaMon : Form
    {
        public Form4SuaMon()
        {
            InitializeComponent();
        }
        DataAccess ac = new DataAccess();
        BLL.BLL business = new BLL.BLL();
        private void btreset_Click(object sender, EventArgs e)
        {
            tbTinChi.Text = "";
        }

        private void Form4SuaMon_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'khoaDataSet.tblKhoa' table. You can move, or remove it, as needed.
            this.tblKhoaTableAdapter.Fill(this.khoaDataSet.tblKhoa);
            // TODO: This line of code loads data into the 'quanLyLichDayDataSet8.tblBoMon' table. You can move, or remove it, as needed.
            //this.tblBoMonTableAdapter.Fill(this.quanLyLichDayDataSet8.tblBoMon);
            // TODO: This line of code loads data into the 'quanLyLichDayDataSet7.tblKhoa' table. You can move, or remove it, as needed.
            //this.tblKhoaTableAdapter.Fill(this.quanLyLichDayDataSet7.tblKhoa);
            try
            {
                string sql = "select TenMon,TenBoMon,SoTinChi from tblBoMon bm,tblMon m where bm.IDBoMon=m.IDBoMon";
                dataGridView1.DataSource = business.ShowData(sql);
                dataGridView1.Show();

            }
            catch { } 

        }

        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                //this.tblKhoaTableAdapter.FillBy(this.quanLyLichDayDataSet7.tblKhoa);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string IDKhoa = cbKhoa.SelectedValue.ToString();
                string sql = "select * from tblBoMon where IDKhoa='" + IDKhoa + "'";
                DataTable dt = ac.GetTable(sql);
                cbBoMon.DataSource = dt;
                cbBoMon.DisplayMember = "TenBoMon";
                cbBoMon.ValueMember = "IDBoMon";
            }
            catch { };
            try
            {
                string IDKhoa = cbKhoa.SelectedValue.ToString();
                string sql3 = "select TenMon,TenBoMon,SoTinChi from tblBoMon bm,tblMon m where bm.IDBoMon=m.IDBoMon and IDKhoa='" + IDKhoa + "'";
                dataGridView1.DataSource = business.ShowData(sql3);
            }
            catch
            {

            }
            try
            {
                //string IDBoMon = cbBoMon.SelectedValue.ToString();
                string IDKhoa1 = cbKhoa.SelectedValue.ToString();
                string sql2 = "select * from tblMon m,tblBoMon bm,tblKhoa khoa where m.IDBoMon=bm.IDBoMon and bm.IDKhoa=khoa.IDKhoa and khoa.IDKhoa='" + IDKhoa1 + "'";
                DataTable dt1 = ac.GetTable(sql2);
                cbMaMon.DataSource = dt1;
                cbMaMon.DisplayMember = "TenMon";
                cbMaMon.ValueMember = "IDMon";
            }
            catch { }
        }

        private void cbBoMon_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string IDBoMon = cbBoMon.SelectedValue.ToString();
                string sql = "select TenMon,TenBoMon,SoTinChi from tblBoMon bm,tblMon m where bm.IDBoMon=m.IDBoMon and m.IDBomon='" + IDBoMon + "'";
                dataGridView1.DataSource = business.ShowData(sql);
            }
            catch { }

            
        }

        private void btSua_Click(object sender, EventArgs e)
        {

        }
    }
}
